<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('学生列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>登录账号：</label>
                                <input type="text" name="loginName"/>
                            </li>
                            <li>
                                <label>贫困等级：</label>
                                <select name="poor" th:with="type=${@dict.getType('wst_student_poor')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>专业：</label>
                                <input type="text" name="profession"/>
                            </li>
                            <li>
                                <label>班级：</label>
                                <input type="text" name="grade"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="wstudy:student:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.editTab()" shiro:hasPermission="wstudy:student:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="wstudy:student:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-info" onclick="$.table.importExcel()" shiro:hasPermission="system:user:import">
<!--                <a class="btn btn-info" onclick="importExcel()" shiro:hasPermission="system:user:import">-->
                    <i class="fa fa-upload"></i> 导入
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="wstudy:student:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('wstudy:student:edit')}]];
        var removeFlag = [[${@permission.hasPermi('wstudy:student:remove')}]];
        var poorDatas = [[${@dict.getType('wst_student_poor')}]];
        var specialtypeDatas = [[${@dict.getType('wst_student_specialtype')}]];
        var prefix = ctx + "wstudy/student";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                importUrl: prefix + "/importData",
                modalName: "学生",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'studentId',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'postId',
                    title: 'postId',
                    visible: false
                },
                {
                    field: 'loginName',
                    title: '登录名称',
                },
                {
                    field: 'userName',
                    title: '名称',
                },
                {
                    field: 'poor',
                    title: '贫困等级',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(poorDatas, value);
                    }
                },
                {
                    field: 'specialtype',
                    title: '特殊群体类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(specialtypeDatas, value);
                    }
                },
                {
                    field: 'credit',
                    title: '信用分'
                },
                {
                    field: 'status',
                    title: '状态',
                    visible: false
                },
                {
                    field: 'profession',
                    title: '专业'
                },
                {
                    field: 'grade',
                    title: '班级'
                },
                {
                    field: 'bankCard',
                    title: '银行卡'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs " href="javascript:void(0)" onclick="details(\'' + row.studentId + '\')"><i class="fa fa-search"></i>详情</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.studentId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.studentId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        function details(id) {
            $.modal.openTab("详情",prefix+"/details/"+id);
        }
        function importExcel() {
            parent.layer.open({
                type: 2,
                area: ['400px','300px'],
                fix: false,
                maxmin: true,
                shade: 0.3,
                title: '评分',
                content: "/wstudy/student/importStudent",
                btn: ['确定','关闭'],
                shadeClose: true
                ,yes:function(index,layero){
                    var iframeWin = parent.window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：

                }
                ,cancel: function(index) {
                    return true;
                }
            });
        }
        function downloadTemplate(){
            let url = "/templates/student.xlsx";
            let name = "导入学生数据模板.xlsx"
            window.location.href =  "/wstudy/student/downloadTemplate?resource=" + url+"&downloadName="+name;
        }
    </script>
     <!-- 导入区域 -->
     <script id="importTpl" type="text/template">
         <form enctype="multipart/form-data" class="mt20 mb10">
             <div class="col-xs-offset-1">
                 <input type="file" id="file" name="file"/>
                 <div class="mt10 pt5">
                     <input type="checkbox" id="updateSupport" name="updateSupport" title="如果登录账户已经存在，更新这条数据。"> 是否更新已经存在的用户数据
                     &nbsp;	<a onclick="downloadTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
                 </div>
                 <font color="red" class="pull-left mt10">
                     提示：仅允许导入“xls”或“xlsx”格式文件！
                 </font>
             </div>
         </form>
     </script>
</body>
</html>